package tvv.levelup.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tvv.levelup.models.News;
import tvv.levelup.repository.NewsRepository;

import java.util.List;

/**
 * Created by VLAD on 09.09.2014.
 */
@Service
public class NewsService implements INewsService{

    @Autowired
    private NewsRepository newsRepository;

    @Override
    public News saveNews(String text) {
        return newsRepository.save(new News(text));
    }

    @Override
    public void deleteNews(News news){
        newsRepository.delete(news);
    }

    @Override
    public News findNewsById(long id){
        return newsRepository.findOne(id);
    }

    @Override
    public News updateNews(News news){
        return newsRepository.save(news);
    }

    @Override
    public List<News> findAllNews() {
        return (List)newsRepository.findAll();
    }
}
